﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;

namespace Web.seatservices
{
    public partial class NumberQuery : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                this.tab1.Visible = true;
                this.tab2.Visible = false;

                //QueryData();
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            bool isLogin = false;
            string strLoginMessage = "登录失败";
            #region 检测登录账号密码是否正确

            Hashtable param = new Hashtable();
            param["username"] = this.txb_username.Text;
            //param["userpwd"] = txb_userpwd.Text;
            Hashtable user = ERMap.ERMapHelper.getmodel("sys_users", param);
            
            

            if (user == null)
            {
                strLoginMessage = "用户不存在";
                Commons.MessageBox.Show(this, "登录失败," + strLoginMessage);
                return;
            }
           
            Dx.ZcEncrypt.Encrypt3DES encrypt = new Dx.ZcEncrypt.Encrypt3DES();
            //El6WuA4jUzKLbI7aQicoCkHD7B7PAxW14sni/iaQ9NMC2rS1WD1m8g==  初始密码123456
            if (!encrypt.ValidPwdBy3des(this.txb_pwd.Text, Commons.StrUtil.FormatValue(user["userpwd"])))
            {
                strLoginMessage="密码错误";
                Commons.MessageBox.Show(this,"登录失败,"+strLoginMessage);
                return;
            }

            isLogin = true;
            strLoginMessage = "登录成功";

            #endregion

            //这里检测用户名密码是否正确
            if (isLogin==true)//如果用户信息提交正确，则在页面中列出所有用户可查看通讯录信息
            {
                Session["tmpuser"] = user;;
                    
                //Commons.MessageBox.Show(this, "登录成功,这里应展示用户所有可查看的通讯录信息" );
               this.tab1.Visible = false;
               this.tab2.Visible = true;
                QueryData();
            }
            else//如果信息有误提示座席人员用户提交信息不正确
            {

            }
        }

        public override void QueryData()
        {
            //string departmentid = ddl_department.SelectedValue;

            //Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["tmpuserid"]));
            Hashtable user = (Hashtable)Session["tmpuser"];
            DataSet ds = PhoneBook.Group.Employee.queryMyEmployee(Commons.StrUtil.FormatValue(user["userid"]));
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }

    }
}